﻿using System;
using System.Collections.Generic;

using System.Text;

namespace RoughJs.Ast
{
    public abstract class SecurityController
    {
        private static SecurityController global1;
        public static SecurityController global()
        {
            return global1;
        }
        public abstract Object getDynamicSecurityDomain(Object securityDomain);


         public Object callWithDomain(Object securityDomain, Context cx,
                                  Callable callable, Scriptable scope,
                                  Scriptable thisObj,  Object[] args)
    {

        return execWithDomain(cx, scope, new Script1() { callable =callable,thisObj = thisObj,args = args}, securityDomain);
    }

    /**
     * @deprecated The application should not override this method and instead
     * override
     * {@link #callWithDomain(Object securityDomain, Context cx, Callable callable, Scriptable scope, Scriptable thisObj, Object[] args)}.
     */
    public Object execWithDomain(Context cx, Scriptable scope,
                                 Script script, Object securityDomain)
    {
        throw new Exception("callWithDomain should be overridden");
    }
    }
    public class Script1:Script
    {
        public Callable callable;
              public Scriptable thisObj;
              public Object[] args;
        #region Script Members

        public object exec(Context cx, Scriptable scope)
        {
            return callable.call(cx, scope, thisObj, args);
        }

        #endregion
    }
}
